package com.neusoft.neuiotms.dcom.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.auth.common.bean.UserBean;
import com.neusoft.bizcore.web.dto.result.PageResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcom.dto.ServiceLevelDTO;
import com.neusoft.neuiotms.dcom.service.ServiceLevelService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "服务水平管理")
@RequestMapping(value = "/api/w/servicelevel")
@RestController
public class ServiceLevelController {

    @Autowired
    private ServiceLevelService serviceLevelService;

    @ApiOperation("查询所有服务水平")
    @GetMapping
    public ResultListDTO<ServiceLevelDTO> index(final Searchable searchable) {
        return ResultListDTO.success(this.serviceLevelService.index(searchable));
    }

    @ApiOperation("分页查询所有服务水平")
    @GetMapping("/p")
    public PageResultDTO<ServiceLevelDTO> page(final Searchable searchable, final Pageable pageable) {
        return PageResultDTO.success(this.serviceLevelService.page(searchable, pageable));
    }

    @ApiOperation("新增服务水平")
    @PostMapping
    public ResultDTO<ServiceLevelDTO> create(@RequestBody final ServiceLevelDTO dto, final UserBean user) {
        return ResultDTO.success(this.serviceLevelService.create(dto, user));
    }

    @ApiOperation("更新服务水平")
    @PutMapping("/{id}")
    public ResultDTO<ServiceLevelDTO> update(@PathVariable final Long id, @RequestBody final ServiceLevelDTO dto,
            final UserBean user) {
        return ResultDTO.success(this.serviceLevelService.update(id, dto, user));
    }

    @ApiOperation("查看服务水平")
    @GetMapping("/{id}")
    public ResultDTO<ServiceLevelDTO> detail(@PathVariable final Long id) {
        return ResultDTO.success(this.serviceLevelService.detail(id));
    }

    @ApiOperation("更新服务水平浏览量")
    @PutMapping("/update/volume/{id}")
    public ResultDTO<Void> updateReadingVolume(@PathVariable final Long id) {
        this.serviceLevelService.updateReadingVolume(id);
        return ResultDTO.success();
    }

    @ApiOperation("删除服务水平")
    @DeleteMapping("/{id}")
    public ResultDTO<Void> delete(@PathVariable final Long id) {
        this.serviceLevelService.delete(id);
        return ResultDTO.success();
    }

}
